const { API_ASIAPD_URL } = require("../../../utils/wxapi");
const wxapi = require("../../../utils/wxapi")

// pages/digital/collect/collect.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuOfData: null,
    newsOfData: null,
    listOfData: null,
    bodyParams: {
      softDelete: '1',
      worksStatus: '1',
      standby6: '',
    },
    pageParams: {
      pageSize: 3,
      pageNum: 0,
    },
    collectOfData: [
      {
        typeKey: 'photography',
        typeOfData: [
          {
            idKey: '25',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/25/1.jpg',
                      worksName: '《车来车往》',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/25/2.jpg',
                      worksName: '《蜗居》',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
          {
            idKey: '26',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/26/1.jpg',
                      worksName: '人像摄影',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/26/2.jpg',
                      worksName: '孟子雯',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
          {
            idKey: '27',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/27/1.jpg',
                      worksName: '风景摄影',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/27/2.jpg',
                      worksName: '巴音布鲁克草原',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
          {
            idKey: '28',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/28/1.jpg',
                      worksName: '玩具屋',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/28/2.jpg',
                      worksName: '王府中环商业',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
          {
            idKey: '29',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/29/1.jpg',
                      worksName: '太和殿',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/photography/29/2.jpg',
                      worksName: '天坛',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
        ],
      },
      {
        typeKey: 'calligraphy',
        typeOfData: [
          {
            idKey: '15',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/15/1.jpg',
                      worksName: '《国际禁毒日》',
                      standby2: '王金彪',
                    },
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/15/2.jpg',
                      worksName: '《小满正当时 万物皆可期》',
                      standby2: '范江平',
                    },
                  ],
                },
              ],
              seachTotal: 1,
            },
          },
          {
            idKey: '16',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/16/1.jpg',
                      worksName: '《初春小雨》',
                      standby2: '张俊焕',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/16/2.jpg',
                      worksName: '《精气神》',
                      standby2: '张俊焕',
                    },
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/16/3.jpg',
                      worksName: '《灵妙》',
                      standby2: '星弘道',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/16/4.jpg',
                      worksName: '《无尽藏》',
                      standby2: '星弘道',
                    },
                  ],
                },
              ],
              seachTotal: 3,
            },
          },
          {
            idKey: '17',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/17/1.jpg',
                      worksName: '李白诗 《春夜宴桃李园序》',
                      standby2: '李燕生',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/17/2.png',
                      worksName: '《怀念战友》',
                      standby2: '张玉波',
                    },
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/17/3.jpg',
                      worksName: '《小满》',
                      standby2: '杨川',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
          {
            idKey: '18',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/18/1.jpg',
                      worksName: '李白诗 《把酒问月》',
                      standby2: '李燕生',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/18/2.jpg',
                      worksName: '《宁静致远》',
                      standby2: '张琮松',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/18/3.jpg',
                      worksName: '《亚太数字》',
                      standby2: '李燕生',
                    },
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/18/4.jpg',
                      worksName: '宋•陆游《乙卯重五诗》',
                      standby2: '王仲刚',
                    },
                  ],
                },
              ],
              seachTotal: 3,
            },
          },
          {
            idKey: '19',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/19/1.jpg',
                      worksName: '《藏古今学术 聚天地精华》',
                      standby2: '苏士澍',
                    },
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/19/2.jpg',
                      worksName: '《松杉挺立中天月，鸿鹄高鸣半夜霜》',
                      standby2: '周志高',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/19/3.jpg',
                      worksName: '《游于艺》',
                      standby2: '苏士澍',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
          {
            idKey: '32',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/32/1.jpg',
                      worksName: '《春望》',
                      standby2: '安和',
                    }
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/32/2.jpg',
                      worksName: '《春晓》',
                      standby2: '霄鹏',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
          {
            idKey: '33',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/33/1.png',
                      worksName: '《腹有文章气自华》',
                      standby2: '李燕生',
                    },
                    {
                      worksPhoto: '/assets/images/collect/calligraphy/33/2.jpg',
                      worksName: '《立夏》',
                      standby2: '马军',
                    }
                  ],
                },
              ],
              seachTotal: 1,
            },
          },
        ],
      },
      {
        typeKey: 'painting',
        typeOfData: [
          {
            idKey: '20',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/painting/20/1.jpg',
                      worksName: '《山云雨，生万物》',
                      standby2: '张耀伟',
                    },
                  ],
                },
              ],
              seachTotal: 1,
            },
          },
          {
            idKey: '21',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/painting/21/1.jpg',
                      worksName: '小头爸爸',
                      standby2: '孟子雯',
                    },
                    {
                      worksPhoto: '/assets/images/collect/painting/21/2.jpg',
                      worksName: '小头爸爸',
                      standby2: '孟子雯',
                    },
                  ],
                },
              ],
              seachTotal: 1,
            },
          },
          {
            idKey: '22',
            idOfData: {
              seachList: [
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/painting/22/1.jpg',
                      worksName: '《鲲鹏展翅九万里》',
                      standby2: '刘海粟',
                    },
                    {
                      worksPhoto: '/assets/images/collect/painting/22/3.jpg',
                      worksName: '国画',
                      standby2: '李燕生',
                    },
                  ],
                },
                {
                  worksList: [
                    {
                      worksPhoto: '/assets/images/collect/painting/22/2.jpg',
                      worksName: '《峡谷红叶》',
                      standby2: '张雷平',
                    },
                  ],
                },
              ],
              seachTotal: 2,
            },
          },
        ],
      },
    ],
    pageTotal: null,
    typeKey: null,
    idKey: null,
    menuSubId: null,
    worksImgUrl: API_ASIAPD_URL
  },

  /**
   * 获取类别列表
   */
  getWorksType() {
    let menuOfData = [
      { id: 24, typeName: '摄影', typeKey: 'photography', subMenu: [] },
      { id: 12, typeName: '书法', typeKey: 'calligraphy', subMenu: [] },
      { id: 11, typeName: '绘画', typeKey: 'painting', subMenu: [] },
    ]
    for (let typeItem of menuOfData) {
      wxapi.getStNumWorksType({ standby4: typeItem.id }).then(res => {
        if (res.status === 200) {
          let subMenu = res.data;
          subMenu = subMenu.filter(item => { item.typeName = item.typeName.slice(0, 2); return item; })
          typeItem.subMenu = subMenu
          this.setData({
            menuOfData
          })
        }
      })
    }
  },

  /**
   * 获取页面文字内容
   * @param {*} id 
   */
  getNews() {
    wxapi.getNewsMsgById({ id: 164 }).then(res => {
      if (res.status === 200) {
        this.setData({
          newsOfData: res.data
        })
      }
    })
  },

  /**
   * 显示精品收藏
   * @param {*} e 
   */
  showWorksList(e) {
    const typeKey = e.currentTarget.dataset.typeKey;
    const idKey = e.currentTarget.dataset.typeId;
    this.setData({
      menuSubId: idKey
    })
    for (const typeItem of this.data.collectOfData) {
      if (typeItem.typeKey === typeKey) {
        for (const idItem of typeItem.typeOfData) {
          if (idItem.idKey == idKey) {
            const listOfData = idItem.idOfData.seachList.slice(this.data.pageParams.pageNum, this.data.pageParams.pageSize);            
            this.setData({
              listOfData,
              total: idItem.idOfData.seachTotal
            })
            return;
          }
          this.setData({
            listOfData: []
          })
        }
      }
      this.setData({
        listOfData: []
      })
    }

  },

  /**
   * 预览艺术品
   * @param {*} e 
   */
  previewImage(e) {
    const worksItem = e.currentTarget.dataset.worksItem;
    if (worksItem.worksPhoto) {
      wx.previewMedia({
        sources: [
          {
            url: this.data.worksImgUrl + worksItem.worksPhoto,
            type: 'image'
          }
        ],
      })
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getWorksType();
    this.getNews();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})